import 'package:abc/controller/my_likes_controller.dart';
import 'package:abc/model/post_model.dart';
import 'package:abc/view/CustomAppBar.dart';
import 'package:abc/view/common_video_cell.dart';
import 'package:abc/view/net_load_img.dart';
import 'package:abc/view/pagination_list_view.dart';
import 'package:abc/view/post_cell.dart';
import 'package:abc/view/video_model.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MyLikesPage extends GetView<MyLikesController> {
  const MyLikesPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (!Get.isRegistered<MyLikesController>()) {
      Get.put(MyLikesController());
    }
    return DefaultTabController(
      length: 5, //
      child: Scaffold(
        backgroundColor: const Color(0xFF0E0F26), // 深色背景
        body: Column(
          children: [
            CustomAppBar(
              title: "我的喜欢",
              onBack: () {
                Get.back();
              },
            ),
            _buildTabBar(), // TabBar
            // TabBarView (内容区域)
            Expanded(
              child: TabBarView(
                children: [
                  // _AccountPasswordView(), // 账号密码视图
                  // _QRCodeRecoveryView(), // 二维码凭证视图
                  _animeWidget(),
                  _mangaWidget(),
                  _longVideoWidget(),
                  _shortVideoWidget(),
                  _postWidget(),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildTabBar() {
    const double indicatorTopPadding = 54.0;
    return SizedBox(
      height: 57,
      child: TabBar(
        padding: EdgeInsets.all(0),
        labelPadding: EdgeInsets.zero,
        dividerHeight: 0.5,
        indicatorPadding: EdgeInsets.fromLTRB(
          0.0,
          indicatorTopPadding,
          0.0,
          0.0,
        ),
        indicator: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.vertical(top: Radius.circular(2)),
        ),

        indicatorSize: TabBarIndicatorSize.label,
        labelStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
        unselectedLabelStyle: const TextStyle(
          fontSize: 14,
          fontWeight: FontWeight.w500,
        ),
        labelColor: Colors.white,
        unselectedLabelColor: Colors.white54,
        tabs: const [
          Tab(text: '动漫'),
          Tab(text: '漫画'),
          Tab(text: '长视频'),
          Tab(text: '短视频'),
          Tab(text: '帖子'),
        ],
        onTap: (value) {
          controller.switchTab(value);
        },
      ),
    );
  }

  //动漫
  Widget _animeWidget() {
    return PaginationListView<VideoModel>(
      controller: controller.videoController,
      itemBuilder: _buildAnimeVideoItem,
      viewType: PaginationViewType.gridView,
      gridConfig: PaginationGridConfig(
        crossAxisCount: 2,
        crossAxisSpacing: 12.0,
        mainAxisSpacing: 12.0,
        mainAxisExtent: animeLayoutConfig.getImageHeight,
      ),
      pageSize: 20,
      enableRefresh: true,
      padding: const EdgeInsets.only(top: 6, bottom: 10, left: 16, right: 16),
    );
  }

  // 构建视频项
  Widget _buildAnimeVideoItem(
    BuildContext context,
    VideoModel video,
    int index,
  ) {
    return CommonVideoCell(
      video: video,
      layoutType: CommonVideoCellType.AnimeLayout,
      layoutConfig: animeLayoutConfig,
      onTap: () {
        // 注意：由于项目中没有VideoDetailPage，这里暂时留空
        // Navigator.of(context).push(
        //   MaterialPageRoute(
        //     builder: (context) => VideoDetailPage(
        //       videoModel: video,
        //       menu: widget.menu,
        //     ),
        //   ),
        // );
      },
    );
  }

  //漫画
  Widget _mangaWidget() {
    return PaginationListView<VideoModel>(
      controller: controller.videoController,
      itemBuilder: _buildMangaVideoItem,
      viewType: PaginationViewType.gridView,
      gridConfig: PaginationGridConfig(
        crossAxisCount: 3,
        crossAxisSpacing: 12.0,
        mainAxisSpacing: 12.0,
        mainAxisExtent: threeLayoutConfig.getImageHeight,
      ),
      pageSize: 20,
      enableRefresh: true,
      padding: const EdgeInsets.only(top: 6, bottom: 10, left: 16, right: 16),
    );
  }

  // 构建视频项
  Widget _buildMangaVideoItem(
    BuildContext context,
    VideoModel video,
    int index,
  ) {
    return CommonVideoCell(
      video: video,
      layoutType: CommonVideoCellType.MangaLayout,
      layoutConfig: threeLayoutConfig,
      onTap: () {
        // 注意：由于项目中没有VideoDetailPage，这里暂时留空
        // Navigator.of(context).push(
        //   MaterialPageRoute(
        //     builder: (context) => VideoDetailPage(
        //       videoModel: video,
        //       menu: widget.menu,
        //     ),
        //   ),
        // );
      },
    );
  }

  //长视频
  Widget _longVideoWidget() {
    return PaginationListView<VideoModel>(
      controller: controller.videoController,
      itemBuilder: _buildLongVideoItem,
      viewType: PaginationViewType.gridView,
      gridConfig: PaginationGridConfig(
        crossAxisCount: 1,
        crossAxisSpacing: 12.0,
        mainAxisSpacing: 12.0,
        mainAxisExtent: oneLayoutConfig.getImageHeight,
      ),
      pageSize: 20,
      enableRefresh: true,
      padding: const EdgeInsets.only(top: 6, bottom: 10, left: 16, right: 16),
    );
  }

  // 构建视频项
  Widget _buildLongVideoItem(
    BuildContext context,
    VideoModel video,
    int index,
  ) {
    return CommonVideoCell(
      video: video,
      layoutType: CommonVideoCellType.LongVideoLayout,
      layoutConfig: oneLayoutConfig,
      onTap: () {
        // 注意：由于项目中没有VideoDetailPage，这里暂时留空
        // Navigator.of(context).push(
        //   MaterialPageRoute(
        //     builder: (context) => VideoDetailPage(
        //       videoModel: video,
        //       menu: widget.menu,
        //     ),
        //   ),
        // );
      },
    );
  }

  //短视频
  Widget _shortVideoWidget() {
    return PaginationListView<VideoModel>(
      controller: controller.videoController,
      itemBuilder: _buildShortVideoItem,
      viewType: PaginationViewType.gridView,
      gridConfig: PaginationGridConfig(
        crossAxisCount: 2,
        crossAxisSpacing: 12.0,
        mainAxisSpacing: 12.0,
        mainAxisExtent: twoLayoutConfig.getImageHeight,
      ),
      pageSize: 20,
      enableRefresh: true,
      padding: const EdgeInsets.only(top: 6, bottom: 10, left: 16, right: 16),
    );
  }

  // 构建视频项
  Widget _buildShortVideoItem(
    BuildContext context,
    VideoModel video,
    int index,
  ) {
    return CommonVideoCell(
      video: video,
      layoutType: CommonVideoCellType.ShortVideoLayout,
      layoutConfig: twoLayoutConfig,
      onTap: () {
        // 注意：由于项目中没有VideoDetailPage，这里暂时留空
        // Navigator.of(context).push(
        //   MaterialPageRoute(
        //     builder: (context) => VideoDetailPage(
        //       videoModel: video,
        //       menu: widget.menu,
        //     ),
        //   ),
        // );
      },
    );
  }

  // 为帖子tab构建页面
  Widget _postWidget() {
    return PaginationListView<Post>(
      controller: controller.postController,
      itemBuilder: (context, post, index) => PostCell(post: post),
      viewType: PaginationViewType.listView,
      pageSize: 20,
      enableRefresh: true,
      padding: const EdgeInsets.only(top: 6, bottom: 10, left: 16, right: 16),
    );
  }
}


